import Vue from 'vue'
import Router from 'vue-router'
import { constantRouterMap, asyncRouterMap } from '@/config/router.config'

// hack router push callback
const originalPush = Router.prototype.push
Router.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(Router)

const R = new Router({
  mode: 'history',
  routes: constantRouterMap 
  // routes: constantRouterMap.concat(asyncRouterMap)
})
R.afterEach((to, from) => {
  // to and from are both route objects.
  if(to.query.addr){
    let _ad = to.query.addr
    to.meta.title = `项目细节(${_ad})`
  }

})

export default R
